package com.smallchange.OOP;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Scanner;

/**
 * Enjoy programming!!!
 * Time: 2022/1/4 -  23:52
 */
public class SmallChangeSysOOP {

    boolean loop = true;
    Scanner scanner = new Scanner(System.in);
    String key = "";

    String details = "--------------------零钱通明细------------------";
    double money = 0;
    double balance = 0;
    Date date = null;//date 是 java.util.Date 类型，表示日期
    SimpleDateFormat sdf = new SimpleDateFormat("yyy-MM-dd HH:mm");

    String note = "";

    public void mainMenu() {
        System.out.println("显示零钱通菜单：");
    }

    public void detail() {
        System.out.println(details);
    }

    public void income() {
        System.out.println("2 收益入账金额：");
        money = scanner.nextDouble();
        //money 的范围应该校验 -》
        //老师思路
        //找出不正确金额的条件，然后给出提示，就直接break
        if (money <= 0) {
            System.out.println("收益入账金额需要大于0");
            return;
        }
        balance += money;

//                 拼接收益入账信息到 details
        date = new Date();//获取当前日期
        details += "\n收益入账\t+" + money + "\t" + sdf.format(date) + "\t" + balance;
    }

    public void pay() {
        System.out.print("消费金额:");
        money = scanner.nextDouble();
        //money 的范围应该校验 -》
        //找出金额不正确的情况
        if (money <= 0 || money > balance) {
            System.out.println("您的消费金额应该在 0-" + balance);
            return;
        }
        System.out.print("消费说明：");
        note = scanner.next();
        balance -= money;
        date = new Date();
        details += "\n" + note + "\t-" + money + "\t" + sdf.format(date) + "\t" + balance;
    }

    public void exit() {
        String choice = "";
        while (true) {
            System.out.println("你确定要退出吗？y/n");
            choice = scanner.next();
            if ("y".equals(choice) || "n".equals(choice)) {
                break;
            }
        }
        if (choice.equals("y")) {
            loop = false;
        }
    }
}
